# !/usr/bin/env python
# -*- coding: utf-8 -*-

# @File   : urlpathutil.py
# @Time   : 2022/5/31 7:20 下午
# @Author : yujianhui
from urllib.parse import urlparse, parse_qsl, ParseResult,urlencode,unquote

# 解析url
def parse(url:str)->ParseResult:
    return urlparse(url)

# 从url中获取path
def get_path_from_url(url:str)->dict[str:str]:
    paser_result=parse(url)
    path=parse_qsl(paser_result.path)
    return dict(path)

# 字典反解析成path
def get_path_from_dict(path:dict)->str:
    return urlencode(path)

# 字典反解析成query
def get_query_from_dict(query:dict)->str:
    return unquote(get_path_from_dict(query))






if __name__=='__main__':
    # url = 'https://www.baidu.com/path?t=${path}&m=${type}&f=${module}&ishttps=1'
    # paser_result = parse(url)
    # query = parse_qsl(paser_result.query)
    # print(dict(query))

    # query=get_query_from_dict(dict(query))
    # print(query)
    # paser_result.query=query
    # print(urlunparse(paser_result))
    pass